﻿@using Matrix.MaKaYunShang.Model.Wechat
@{
    ViewBag.Title = "核销卡劵";
    ViewBag.PathToBtn = "/UserCard/List";
    ViewBag.TextBtn = "用户卡卷管理";
    Layout = "~/Views/Shared/_Layout.cshtml";

}
<div class="row" style="">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="dataTable_wrapper">
                    <br />
                    <br />
                    <div style=" text-align: center; margin: 0 auto; width: 60%">
                        <input type="tel" class="form-control " name="CardCode" id="CardCode" style="text-align:center;" placeholder="请输入卡劵Code码" />
                        <a class="btn btn-primary " style="display: none;" name="get_HYK" id="get_HYK">扫一扫</a>
                    </div>
                    <br />
                    <div style=" text-align: center; margin: 0 auto; width:30%">
                        
                    </div>
                    <br />
                    <div style=" text-align: center; margin: 0 auto; width:30%">
                        <a class="btn btn-primary col-lg-10" name="Write_off" id="Write_off">确认核销</a>
                    </div>
                    <br />
                    <br />
                </div>
            </div>
        </div>
    </div>
</div>
<script src="~/Content/bootstrap-datetimepicker/jquery/jquery-1.8.3.min.js"></script>
<script src="/Content/alertify-js/js/alertify.js"></script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
<script>
    wx.config({
        debug: false,
        appId: '@Model.AppId',
        timestamp: '@Model.Timestamp',
        nonceStr: '@Model.Nonstr',
        signature: '@JsTicket.getSign(Model.Nonstr, Model.JsapiTicket, Model.Timestamp, Request.Url.AbsoluteUri)',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'onMenuShareQZone',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onVoiceRecordEnd',
            'playVoice',
            'onVoicePlayEnd',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ]
    });
</script>
<script type="text/javascript">
    var ua = window.navigator.userAgent.toLowerCase();
    if (ua.match(/MicroMessenger/i) == 'micromessenger') {
        $("#get_HYK").attr("style", "display:block");
    }
    //核销卡劵
    $("#Write_off").click(function () {
        var cardCode = $("#CardCode").val();
        if (cardCode == null || cardCode == "") {
            alert("请输入卡券编号");
            return false;
        }
        alertify.okBtn("确定").cancelBtn("取消").confirm("确认要核销吗", function () {
        $.ajax({
            type: "POST",
            url: '/Verify/AjaxVerify',
            data: { code: cardCode },
            error: function (request) {
                alertify.alert("服务器错误!");
            },
            success: function (data) {
                if (data.Status) {
                    //查询卡劵状态
                    //location.href = "/Merchant/CardVerfyResult?code=" + cardCode;
                    alertify.alert(data.Message);
                } else {
                    alertify.alert(data.Message);
                }
            }
             });
        });
    });
</script>
<script>
    $(function () {
        document.querySelector('#get_HYK').onclick = function () {
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["qrCode", "barCode"], 
                success: function (res) {
                    alertify.okBtn("确定").cancelBtn("取消").confirm("确认要核销吗", function () {
                        var result = res.resultStr;
                        $.ajax({
                            type: "POST",
                            url: '/Verify/AjaxVerify',
                            data: { code: result },
                            error: function (request) {
                                alertify.alert("服务器错误!");
                            },
                            success: function (data) {
                                if (data.Status) {
                                    alertify.alert(data.Message);
                                } else {
                                    alertify.alert(data.Message);
                                }
                            }
                        });
                    });
                }
            });
        };
    });
</script>
